package cn.yusei.teamTribe.dao.team;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.yusei.teamTribe.dao.team.po.TeamPhotoPO;

@Mapper
public interface TeamPhotoDAO {

	String TEAM_PHOTO_TABLE = " r_photo_team_user_album ";
	String INSERT_FIELDS = " (team_id, album_id, user_id, file_id) ";
	String SELECT_FIELDS = " team_id, album_id, user_id, file_id, create_time ";
	
	@Insert({"insert into", TEAM_PHOTO_TABLE, INSERT_FIELDS, "values (#{teamId}, #{albumId}, #{userId}, #{fileId})"})
	void insert(TeamPhotoPO teamPhotoPO);
	
	@Select({"select file_id from", TEAM_PHOTO_TABLE,
		"where deleted = 0 and team_id = #{teamId} and album_id = #{albumId} limit #{offset}, #{num}"})
	String[] select(@Param("teamId") int teamId, @Param("albumId") int albumId,
			@Param("offset") int offset, @Param("num") int num);
	
	@Update({"update", TEAM_PHOTO_TABLE,
		"set deleted = 1 where team_id = #{teamId} and album_id = #{albumId} and file_id = #{fileId} limit 1"})
	void delete(TeamPhotoPO teamPhotoPO);
	
	@Update({"update", TEAM_PHOTO_TABLE, "set deleted = 1 where team_id = #{teamId} and album_id = #{albumId}"})
	void deleteAlbum(@Param("teamId") int teamId, @Param("albumId") int albumId);
}
